<template>
    <view class="topic-square-detail">  
        <headerVue :backOpBg="true" bgColor="transparent" />
         <!-- 主图区域 -->
         <view class="main-image-section">
            <u-image 
                :src="detail.image_url" 
                mode="aspectFill" 
                width="100%" 
                height="480rpx"
                radius="0"
            ></u-image>
        </view>
        <view class="content-section">
            <view class="content-header">
                <u-image :src="IMAGE_URL + '/static/community/icon18.png'" width="32rpx" height="32rpx"></u-image>
                <view class="content-title">{{ detail.title }}</view>
            </view>
            <view class="author-info">
                <view class="author-info-item">
                    <view class="author-info-item-avatar">
                        <u-image :src="detail.pic" width="32rpx" height="32rpx"></u-image>
                    </view>
                    <view class="author-info-item-name">{{ detail.author }}</view>
                    <view class="author-info-item-time">{{ detail.publish_time }}</view>
                </view>
            </view>
            <view class="content-content">
                <u-parse :content="detail.content" />
            </view>
        </view>
    </view>
</template>
<script>
import headerVue from '@/components/header.vue'
import { getCommunitynewsPolicyDetail } from '@/api/index.js'
import { formatPublishTime } from '@/utils/utils.js'
import appConfig from '@/config/app.js'
export default {
    components: { headerVue },
    data() {
        return {
            IMAGE_URL: appConfig.IMAGE_URL,
            id: '',
            detail: {},
            loading: true
        }
    },
    onLoad(option) {
        this.getCommunitynewsPolicyDetailEvent(option.id)
    },
    methods: {
        async getCommunitynewsPolicyDetailEvent(id) {
            const res = await getCommunitynewsPolicyDetail({id})
            const list = res.data || {}
            // 后端可能返回字符串/空/null/数组，统一为数组
            let imgs = []
            const raw = list.image_urls
            if (Array.isArray(raw)) {
                imgs = raw
            } else if (typeof raw === 'string') {
                const s = raw.trim()
                if (s) {
                    try {
                        const parsed = JSON.parse(s)
                        if (Array.isArray(parsed)) imgs = parsed
                    } catch (e) {
                        // 非JSON字符串，尝试逗号分隔
                        imgs = s.includes(',') ? s.split(',').map(x => x.trim()).filter(Boolean) : (s ? [s] : [])
                    }
                }
            }
            list.image_urls = imgs
            // 格式化为“YYYY年MM月DD日 HH:mm”
            if (list.publish_time) {    
                list.publish_time = formatPublishTime(list.publish_time, 'YYYY年MM月DD日 HH:mm')
            }
            this.detail = list
        },
    }
}
</script>
<style lang="scss" scoped>
    .topic-square-detail {
        position: relative;
        width: 100%;
        min-height: 100vh;
    }

    // 主图区域
.main-image-section {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 480rpx;
    z-index: 1;
}

    .content-section {
        position: relative;
        width: 100%;
        height: 100%;
        z-index: 2;
        background-color: #fff;
        padding: 28rpx 32rpx;
        margin-top: 342rpx;
        box-sizing: border-box;
    }

    .content-header {
        position: relative;
        width: 100%;
        height: 100%;
        z-index: 2;
        display: flex;
        align-items: center;
    }

    .content-title {
        font-size: 32rpx;
        font-weight: bold;
        color: #333;
        margin-left: 12rpx;
    }

    .author-info {
        position: relative;
        width: 100%;
        z-index: 2;
        margin: 24rpx 0 28rpx;
    }

    .author-info-item {
        position: relative;
        width: 100%;
        z-index: 2;
        display: flex;
        align-items: center;
        justify-content: flex-start;
    }

    .author-info-item-avatar {
        position: relative;
        z-index: 2;
    }

    .author-info-item-name {
        position: relative;
        z-index: 2;
        margin:0 28rpx 0 4rpx;
        font-size: 24rpx;
        color: #999999;
    }

    .author-info-item-time {
        position: relative;
        z-index: 2;
        font-size: 24rpx;
        color: #999999;
    }
    
    // 底部交互栏样式
    .interaction-footer {
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: #fff;
    }
    
    .input-section {
        width: 392rpx;
        height: 72rpx;
        background: #F6F6F6;
        border-radius: 60rpx 60rpx 60rpx 60rpx;
    }
    
    .comment-input {
        width: 392rpx;
        background: #F6F6F6;
        border-radius: 60rpx 60rpx 60rpx 60rpx;
        padding: 12rpx 24rpx;
        box-sizing: border-box;
        font-size: 26rpx;
        color: #999;
        min-height: 68rpx;
        line-height: 1.4;
    }
    
    .action-section {
        display: flex;
        align-items: center;
        gap: 20rpx;
    }
    
    .action-item {
        display: flex;
        align-items: center;
        gap: 8rpx;
    }
    
    .action-text {
        font-size: 24rpx;
        color: #333;
        font-weight: 500;
    }
</style>